﻿using DailyRssDownload.Lib;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Diagnostics;
namespace TestDailyRssDownloadLib
{
    
    
    /// <summary>
    ///This is a test class for EntryTest and is intended
    ///to contain all EntryTest Unit Tests
    ///</summary>
	[TestClass()]
	public class EntryTest {


		private TestContext testContextInstance;

		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext {
			get {
				return testContextInstance;
			}
			set {
				testContextInstance = value;
			}
		}

		#region Additional test attributes
		// 
		//You can use the following additional attributes as you write your tests:
		//
		//Use ClassInitialize to run code before running the first test in the class
		//[ClassInitialize()]
		//public static void MyClassInitialize(TestContext testContext)
		//{
		//}
		//
		//Use ClassCleanup to run code after all tests in a class have run
		//[ClassCleanup()]
		//public static void MyClassCleanup()
		//{
		//}
		//
		//Use TestInitialize to run code before running each test
		//[TestInitialize()]
		//public void MyTestInitialize()
		//{
		//}
		//
		//Use TestCleanup to run code after each test has run
		//[TestCleanup()]
		//public void MyTestCleanup()
		//{
		//}
		//
		#endregion

		/// <summary>
		///A test for GetImageNameFromImageUrl
		///</summary>
		[TestMethod()]
		public void GetImageNameFromImageUrlTest() {
			Debug.WriteLine("hi");
			Debug.WriteLine("Ho");

			string strUrl = "http://ad.doubleclick.net/ad/N1727.wp/B2565687.13;sz=1x1;ord=%n?";
			string expected = "B2565687.13;sz=1x1;ord=%n?";
			string actual;
			actual = Entry.GetImageNameFromImageUrl(strUrl);
			Assert.AreEqual(expected, actual);

			Debug.WriteLine("Done!");
		}

		/// <summary>
		///A test for GetUrlFromImageElement
		///</summary>
		[TestMethod()]
		[Description("Tests single quotes instead of double quotes")]
		public void GetUrlFromImageElementTest() {
			string strImgElement = "<img border='0' src='http://ad.doubleclick.net/ad/N1727.wp/B2565687.13;sz=1x1;ord=%n?'>";
			string expected = "http://ad.doubleclick.net/ad/N1727.wp/B2565687.13;sz=1x1;ord=%n?";
			string actual;
			actual = Entry.GetUrlFromImageElement(strImgElement);
			Assert.AreEqual(expected, actual);
		}

		/// <summary>
		///A test for ExtractContentFromHtml
		///</summary>
		[TestMethod()]
		[DeploymentItem("DailyRssDownloadLib.dll")]
		public void ExtractContentFromHtmlTest_WithMarkers() {
			string strHtml = "<html><head><title>MyTitle</title></head><body id=\"PageArticle\"><p>Stuff</p><div style=\"clear:both\"></div><div id=\"article_body\" style=\"padding-left:10px;\"><p>Blah blah blah the content.</p></div><!-- sphereit end --><br clear=\"all\"><p>Include Me</p><div style=\"clear:both\"></div><p>Ignore Footer</p></body></html>";
			string strContentStartMarker = @"\<div id=\""article_body\""[^\>]*\>";
			string strContentEndMarker = @"\<div style=\""clear:both\""\>";
			string expected = "<p>Blah blah blah the content.</p></div><!-- sphereit end --><br clear=\"all\"><p>Include Me</p>";
			string actual;
			actual = Entry_Accessor.ExtractContentFromHtml(strHtml, strContentStartMarker, strContentEndMarker);
			Assert.AreEqual(expected, actual);
		}

		/// <summary>
		///A test for ExtractContentFromHtml
		///</summary>
		[TestMethod()]
		[DeploymentItem("DailyRssDownloadLib.dll")]
		public void ExtractContentFromHtmlTest_WithoutMarkers() {
			string strHtml = "<html><head><title>MyTitle</title></head><body id=\"PageArticle\"><p>Stuff</p><div style=\"clear:both\"></div><div id=\"article_body\" style=\"padding-left:10px;\"><p>Blah blah blah the content.</p></div><!-- sphereit end --><br clear=\"all\"><p>Include Me</p><div style=\"clear:both\"></div><p>Ignore Footer</p></body></html>";
			string strContentStartMarker = "";
			string strContentEndMarker = "";
			string expected = "<p>Stuff</p><div style=\"clear:both\"></div><div id=\"article_body\" style=\"padding-left:10px;\"><p>Blah blah blah the content.</p></div><!-- sphereit end --><br clear=\"all\"><p>Include Me</p><div style=\"clear:both\"></div><p>Ignore Footer</p>";
			string actual;
			actual = Entry_Accessor.ExtractContentFromHtml(strHtml, strContentStartMarker, strContentEndMarker);
			Assert.AreEqual(expected, actual);
		}

		/// <summary>
		///A test for MakeOsSafeName
		///</summary>
		[TestMethod()]
		public void MakeOsSafeNameTest() {
			string str = @"a\b/c:d*e?f""g<h>i|j.k l'm";
			string expected = "abcdefghijklm";
			string actual;
			actual = Entry.MakeOsSafeName(str);
			Assert.AreEqual(expected, actual);
		}

		/// <summary>
		///A test for ExtractSummaryFromContent
		///</summary>
		[TestMethod()]
		[DeploymentItem("DailyRssDownloadLib.dll")]
		public void ExtractSummaryFromContentTest() {
			string strHtmlContent = @"<div style=""padding-left: 10px;""><font size=""2""><div id=""byline"">By <a href=""http://projects.washingtonpost.com/staff/email/jonathan+weisman/"" title=""Send an e-mail to Jonathan Weisman"">Jonathan Weisman</a></div>Washington Post Staff Writer<br />Tuesday, January 29, 2008; 5:17 PM </font><p></p></div><div id=""article_body"" style=""padding-left: 10px;""><p>The House today overwhelmingly approved a $146 billion shot in the arm for the nation&#39;s ailing economy, sending a stimulus package to the Senate with a bipartisan appeal to senators not to slow the bill with significant changes.</p></div>";
			int intChars = 100;
			string expected = "By Jonathan Weisman Washington Post Staff Writer Tuesday, January 29, 2008; 5:17 PM The House today";
			string actual;
			actual = Entry_Accessor.ExtractSummaryFromContent(strHtmlContent, intChars);
			Assert.AreEqual(expected, actual);
		}

		/// <summary>
		///A test for ExtractSummaryFromContent
		///</summary>
		[TestMethod()]
		[DeploymentItem("DailyRssDownloadLib.dll")]
		public void ExtractSummaryFromContentTest_SmallCharValue() {
			string strHtmlContent = "hi";
			int intChars = 0;
			string expected = "";
			string actual;
			actual = Entry_Accessor.ExtractSummaryFromContent(strHtmlContent, intChars);
			Assert.AreEqual(expected, actual);
		}

		/// <summary>
		///A test for ExtractSummaryFromContent
		///</summary>
		[TestMethod()]
		[DeploymentItem("DailyRssDownloadLib.dll")]
		public void ExtractSummaryFromContentTest_LargeCharValue() {
			string strHtmlContent = "hi";
			int intChars = 300;
			string expected = "hi";
			string actual;
			actual = Entry_Accessor.ExtractSummaryFromContent(strHtmlContent, intChars);
			Assert.AreEqual(expected, actual);
		}
	}
}
